<template>
	<view style="padding: 10px;">
		<view style="color: gray;">{{data}}</view>
		<view style="text-align: center;margin-bottom: 10px;">实时监控画面</view>
		<image style="width: 100%;" src="../../static/logo.png"></image>
		
		<button style="margin-top: 10px;" type="primary" @click="postDeviceUnlock">开门</button><!-- 这种写法只有h5平台支持，不跨端，不推荐使用 -->
		
		<view style="margin-top: 30px;font-size: 14px;color: gray;text-align: center;">
			<text>联系客服</text>
			<text style="margin: 0 10px;">|</text>
			<text> 联系物业</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: '',
			}
		},
		onLoad(opts) {

		},
		onShow() {
			let id = uni.getStorageSync('tmp_device_id', 0);
			if (id != 0) {
				let _this = this;
				_this.$api.getDeviceInfo({id: id}).then(res => {
					_this.data = res.data.info;
				})
			}
		},
		methods: {
			postDeviceUnlock() {
				let device_id2 = uni.getStorageSync('tmp_device_id2', 0);
				
				let that = this;
				let proprietor_id = uni.getStorageSync('proprietor_id');
				let uid = uni.getStorageSync('uid');
				uni.showModal({
					title: '是否确认操作',
					success: function(res) {
						if (res.confirm) {
			
							that.$api.postDeviceUnlock({
								uid: uid,
								proprietor_id: proprietor_id,
								device_id2: device_id2
							}).then(res => {
								if (res.meta.code == '000') {
									uni.showToast({
										title: res.meta.msg,
										duration: 2000,
										icon: 'none',
									})
								}
			
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			
			},
		}
	}
</script>

<style>
</style>
